package com.cs.study.homework._0325;

import com.cs.study.homework._0325.util.JdbcUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

public class Demo {
    public static void main(String[] args) throws Exception {
        Connection connection = JdbcUtil.getConnection();
        Statement statement = connection.createStatement();


        ResultSet resultSet = statement.executeQuery("select * from market_region where code like '420%'");

//        while (resultSet.next()) { // next方法 指针后移，返回值：是否还有数据
//            String username = resultSet.getString("username");
//            System.out.println(username);
//        }

        ArrayList<com.cs.study.homework._0325.Region> list = new ArrayList<>();
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            int pid = resultSet.getInt("pid");
            String name = resultSet.getString("name");
            Byte type = resultSet.getByte("type");
            int code = resultSet.getInt("code");

            Region region = new Region(id,pid,name,type,code);
            list.add(region);
        }

        list.forEach(System.out::println);




        statement.close();
        connection.close();
    }
}
